package demo;

import cn.hutool.core.date.DateUtil;
import demo.consumer.MySink;
import demo.consumer.ReceiveService;
import demo.model.Product;
import demo.producer.MySource;
import demo.producer.SenderService;
import demo.transaction.Sender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.messaging.Source;

@EnableBinding(value = {Source.class, Sink.class, MySource.class, MySink.class})
@SpringBootApplication
public class SpringCloudStreamApplication implements CommandLineRunner {

    @Autowired
    private SenderService senderService;

    @Autowired
    private ReceiveService receiveService;

    @Autowired
    private Sender sender;

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudStreamApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        //发送字符串
//        senderService.send("Hello spring cloud stream rocketmq.");

        //发送对象
        /*senderService.sendObject(Product.builder()
                                    .prodCode("p001000")
                                    .prodName("产品1")
                                    .price("365")
                                    .onTime(DateUtil.now())
                                    .downTime(DateUtil.now())
                                    .build(), "myTag");*/

        //senderService.sendTemplate("template meaasge....");

        sender.sendTransactionalMsg("transaction message 1", 1);
        sender.sendTransactionalMsg("transaction message 2", 2);
        sender.sendTransactionalMsg("transaction message 3", 3);
        sender.sendTransactionalMsg("transaction message 4", 4);
    }
}
